package engine.tip.tipItem
{
	import engine.data.ModelLocator;
	import engine.data.ObjectData;
	import engine.data.RoleVo;
	import engine.flag.GameDefine;
	import engine.logic.login.PlayCDTimerLogic;
	import engine.newUi.DetailPropertyLogic;
	import engine.tip.TipsMainLogic;
	
	import newx.BaseObject;
	import newx.com.config.StaticIni;

	/**
	 *装备tips 
	 * @author yanghr
	 * 
	 */	
	public class EquipItem extends BaseTipItem
	{
		/**
		 *装备传承属性 专用 
		 */		
		public static const CURRENT_LEVEL:String="_currentLevel";
		private const MODIFY_TITLE:Object=
			{
				 6:StaticIni.getSwfLangStr("F_Gem_13229"),
				 7:StaticIni.getSwfLangStr("F_Gem_13230"),
				 8:StaticIni.getSwfLangStr("F_Gem_13231"),
				 9:StaticIni.getSwfLangStr("F_Gem_13232")
			};
		private const TYPE_TABLE	:Array	=	["","Phy","Nature","Mist","Fire","Ice","Holy","Dark"];
		private const NORMAL:int	=	0;
		private const MODIFY:int	=	1;
		private const OTHER:int	=	2;
		private const FASHION:int	=	3;
		private var _roleObj:RoleVo;
		protected  var _disCount:Number;
		/**
		 * 需要削弱的属性
		 *生命值=MaxHPAdd
			普攻=PhyDamageAdd
			普防=PhyDefAdd
			绝攻=MagDamageAdd
			绝防=MagDefAdd 
		 */		
		private const DISCOUNTARR:Array=[601,603,604,605,606];
//		private var _addPropObj:Object;
		
		private var _strengthProptMap:Object=new Object;
		public function EquipItem(dataObject:ObjectData=null,data:Object=null)
		{
			super(dataObject,data);
			init();
		}
		protected function init():void 
		{
			_roleObj = ModelLocator.getInstance().scene.Role;
//			_addPropObj	 = StaticIni.getIniObj("AddProp");
		}
		override public function getMainStr():String
		{
			normalPropertyCount=0;
			_disCount=currentDisCount
			var holeCan:String=canModify();
			var holeProperty:String=modifyPropertys() ;
			var fashionPro:String = fashionPropertys() ;
			var aCond:Boolean=(holeCan||holeProperty)
			var isDesc:Boolean =Boolean( desc());
			var proIs:Boolean;
			if(data["EquipType"] =="Fashion")
			{
				proIs =false ;
			}else
			{
				proIs = true ; 
			}
	
			var str:String = getName()+getChangeLine()//+getItemStopTime()+"\n"
//			+(getEqStrength())+""
//			+getEqDamage()+""
//			+getPhyDef()+""
//			+(otherPropertys())+""
			+(proIs?normalPropertys():fashionPro)+""
			+getALine()
			+(holeCan)+""
			+(holeProperty)+""
			+(aCond?getALine():"")
			+(getEqNeedProf())+""
			+(getEqNeedLevel())
			+getALine()
//			+(getEqHardIness())+""
			+getEquipFightScore()+""
			+getPrice()+"\n";
			
			if(isDesc)
			{
				str += getALine()+desc()+getChangeLine();
			}
			
			if(getItemStopTime())
			{
				str +=getALine()+getItemStopTime();
			}
			return str;
			
		}
		public function  desc():String
		{
			if(_data["EquipType"] == GameDefine.EquipType_Fashion)
			{
				return StaticIni.getSwfLangStr("Description_"+_data["ConfigID"]);
			}
			return ""
		}
		public function get currentDisCount():Number
		{
			var currentLevel:int=data[CURRENT_LEVEL];
			var eqLevel:int=_data["NeedLevel"];
			if(!currentLevel||eqLevel<=currentLevel)return 1;
			return (eqLevel-currentLevel)/(eqLevel-1)*.65
		}
		/**
		 *强化 
		 * @return 
		 * 
		 */		
		public function getEqStrength():String
		{
			//显示是否需要强化
			var str:String=""
				
//			if(_data &&	_data["IntensityType"] && 0 != int(_data["IntensityType"]))
			{
				var intensityLevel:int	=	_data["IntensityLevel"] ;
				str	=	str.concat("+"+intensityLevel);
//				if(intensityLevel	<= 0)
//				{
//					//可强化
////					str	=	str.concat("&nbsp;&nbsp;&nbsp;&nbsp;"+ StaticIni.getSwfLangStr("UIStr_1001346") );
//				}
//				else if(intensityLevel	>=	100)
//				{
//					//已强化至顶级
//					str	=	str.concat("&nbsp;&nbsp;&nbsp;&nbsp;"+ StaticIni.getSwfLangStr("UIStr_1001347") );
//				}
//				else
//				{
//					//强化等级
//					str	=	str.concat("&nbsp;&nbsp;&nbsp;&nbsp;"+ StaticIni.getSwfLangStrVar("Upgrade_Level",[intensityLevel]) );
//				}
//				str	=	str.concat("<br>");
				
				//显示装备战斗力
				//str = str.concat( getEquipFightScore( serverObj, configID ) + "<br>" );	
				//装备可强化最高等级
				//var MaxUpLevel:int		=	equipObj.CheckProperties("IntensityMaxLevel") ? equipObj.GetProperties("IntensityMaxLevel") : 0;
//				var MaxUpLevel:String	=	_data["IntensityMaxLevel"]//StaticIni.getIniVar("configID","IntensityMaxLevel");
//				str	=	str.concat(StaticIni.getSwfLangStrVar("Upgrade_Tips_1",[MaxUpLevel]) );
			}
			//else
			//{
			//显示装备战斗力
			//str = str.concat( "<br>" + getEquipFightScore( serverObj, configID ) );	
			//}
			if(intensityLevel)
			return str
			return ""
//			return getChangeLine();
		}
		/**
		 * HardIness 是什么 ？
		 * @return 
		 * 
		 */		
		public function getEqHardIness():String
		{
			//show hardiness
			var	hardiness:String= _data.MaxHardiness;
			var itemHard:String		=		"";
			var str:String	=	"";
			itemHard	=	_data["Hardiness"]?_data["Hardiness"]:_data["MaxHardiness"]
			if(itemHard!=null&&itemHard!="")
			{
				var temp:String				= StaticIni.getSwfLangStr("ItemDes_Hardiness");
				str					= str.concat(temp);
				str					= str.concat(itemHard);
			}
			str					= str.concat("/");
			str					= str.concat(hardiness);
			str					= str.concat("<br>");
			return str;
		}
		/**
		 *装备职业需要 
		 * @return 
		 * 
		 */		
		public function getEqNeedProf():String
		{
			//show profession
			var prof:String		= _data["AdaptProfType"];
			var str:String="";
			if(prof)
			{
				var userProf:String	=	_roleObj.GetPropertiesEx("ProfType");
				var profList:Array	=	prof.split(",");
				var temp:String		= StaticIni.getSwfLangStr("AdaptProfType_" + prof);
				if(profList.indexOf(userProf)>-1)
				{
					str				= str.concat(temp);
				}else
				{
					str				= str.concat("<font color='#f00000'>"+temp+"</font>");
				}
			}
			if(str)
			return str+getChangeLine();
			return "";
		}
		/**
		 *伤害值 
		 * @return 
		 * 
		 */		
		internal function getEqDamage():String
		{
			
				var temp		:String = 	"";
				var str			:String = 	"";
				var tSize		:uint	=	TYPE_TABLE.length;
				
				var mindamage	:String = 	"";
				var maxdamage	:String = 	"";
				
				
				for(var i:uint = 1 ; i< tSize ; i ++)
				{
					mindamage	=	_data["Min"+TYPE_TABLE[i]+"Damage"];
					maxdamage	=	_data["Max"+TYPE_TABLE[i]+"Damage"];
					
					if(maxdamage != null && maxdamage != "" && mindamage != null && mindamage != "")
					{
						str		=	mindamage;
						str		=	str.concat("-");
						str		=	str.concat(maxdamage);					
						temp	=	StaticIni.getSwfLangStr("ItemDes_Damage_"+TYPE_TABLE[i]);
						str 		= str.concat(temp)
						break;
					}
				}
				if(str)
				return str+"<br>";
				return "";
		}
		/**
		 *得到物理防御力 
		 * @return 
		 * 
		 */		
		public function getPhyDef():String
		{
			//show phydef物理防御
			var phydef:String	= _data.PhyDef;
			var str:String="";
			if(phydef != null && phydef != "")
			{
				var temp:String			= StaticIni.getSwfLangStr("ItemDes_PhyDef");
				str				= str.concat(phydef);
				str				= str.concat(temp);
				str				= str.concat("<br>");
			}
			return str
		}
		/**
		 *装备消失时间 
		 * @return 
		 * 
		 */		
		public function getItemStopTime():String
		{
			//持续时间(小时转化成毫秒)
			var validTime	:	Number
			validTime=	_data["ValidTime"] * 60
			if(validTime == 0) return "";
			
			//单位毫秒
			var beginTime	:	Number	=	_data["BeginTime"] * 1000;
			if(!beginTime)
			{
//				var str:String =PlayCDTimerLogic.getInstance().getTimerStr1(validTime);
				return "";
			}
			if(_data["EndTimeFlag"]>0)
			{
				return StaticIni.getSwfLangStr("UIString_1000701"); //已到期	
			}
			var date : Date	=	new Date(beginTime + validTime*1000);
			return StaticIni.getSwfLangStrVar("UIStr_1001353", [date.getFullYear(), date.getMonth() + 1, date.getDate(), date.getHours(), date.getMinutes()]); 
		}
	
		/**
		 *显示可打孔 
		 * @return 
		 * 
		 */		
		public function canModify():String
		{
			var str:String="";
			var holeCountStr:String	=	"";
			var itmpType:String	=	_data["ItemType"];
			var holeCount:int	=	_data["HoleCount"];
			if(itmpType	=="105" || itmpType	=="107")
			{
				if(holeCount <4){
					//可打孔
					holeCountStr	=	StaticIni.getSwfLangStr("F_Gem_13233");
				}else{
					//孔以打满
					holeCountStr	=	StaticIni.getSwfLangStr("F_Gem_13242");
				}
				str	=	str.concat(holeCountStr);
			}
			return str;
		}
		/**
		 *打孔属性 
		 * @return 
		 * 
		 */		
		internal function modifyPropertys():String
		{
			return handlePropertys(MODIFY)
		}
		/**
		 * 时装属性
		 */		
		internal function fashionPropertys():String
		{
			return handlePropertys(FASHION)
		}
		/**
		 *	普通属性
		 * @param configObj
		 * @param special
		 * @return 
		 * 
		 */
		internal function  normalPropertys():String
		{
			return handlePropertys(NORMAL);
		}
		/**
		 *我也不知道是什么属性
		 * 好像这个是强化属性 
		 * 必须在 normalPropertys之前调用
		 * @return 
		 * @see normalPropertys()
		 * 
		 */		
		internal function otherPropertys():String
		{
			return handlePropertys(OTHER)
		}
		protected var normalPropertyCount:int;
		internal function  handlePropertys(type:int):String
		{
			var configObj:Object=_data;

			//颜色
			var color		:int	=	configObj.Color;
			var tips		:String	=	"";
			var property	:String	=	"";
			var configProperty:String=	"";
			var value:int=0;
			var valueStr:String="";
			var obj:Object=StaticIni.getIniObj("ProTipList_"+type)
			for(var i:uint = obj["startNum"] ; i <	int(obj["startNum"])+int(obj["num"]) ; i ++)
			{
				//获取属性
				property	= configObj["AddPropNo"+i];
				//当有属性的时候
				if(property != null && property != "" && property != "0")
				{
					if(type==MODIFY)tips	=	tips.concat(MODIFY_TITLE[i])
					else if(type==NORMAL)normalPropertyCount++;
					configProperty= property.substr(0,3)//_addPropObj[property];
					if(type ==FASHION)
					{
						value=int(property.substr(4))
					}else
					{
						value=int(property.substr(4))+getPropertyNum(i+3);
					}
					
					//装备传承   属性减少
					if(DISCOUNTARR.indexOf(int(configProperty))!=-1	&&	_disCount!=1)
					{
//						valueStr=DetailPropertyLogic.getInstance().outZero(int(value*(1-_disCount))+"");
						valueStr=DetailPropertyLogic.getInstance().outZero(
							int(int(value)-int(_disCount*value))	+""
						);
					}
					else
						valueStr=value+"";
					if(configProperty)
					{
						tips = tips.concat(singleProperty(color,configProperty,valueStr,type));
					}
					else
					{
						tips	=	tips.concat("AddProp 没有",property,"这条属性")+getChangeLine()
					}
//					if(type!=NORMAL)
//						trace("handlePropertys",type,"=>",tips)
					
				}
			}
			if(tips)
			return tips /*+ getChangeLine()*/;
			return "";
			function getPropertyNum(type:int):int
			{
				//获取属性
				var prope:String	= configObj["AddPropNo"+type];
				var num:int
				//当有属性的时候
				if(prope != null && prope != "" && prope != "0")
				{
					num=int(prope.substr(3));
				}
				return num
			}
		}
		/**
		 * 	单一属性
		 * @param color				颜色
		 * @return 
		 * 
		 */
		internal function singleProperty(color : int, type : String,value:*,Ptype:int) : String
		{
			var tips : String = "";
			//属性obj
//			var propertyList : Array	=	property.split(",");
			//属性类型
//			var type : String = propertyList[3];
			//属性值
//			var value : int = propertyList[4];
			
			//有属性的时候
			if(type != null && type != "")
			{
				//加颜色
				tips 	=	con(StaticIni.getSwfLangStrVar("ItemProp_" + type,[value]));
				if(Ptype	==	NORMAL	&&	type	&&	_strengthProptMap	&&	_strengthProptMap[type])
				{
					tips	=	tips.concat(_strengthProptMap[type]);
				}
				else if(Ptype	==	OTHER)
				{
					/*tips	=	tips.concat*/
					_strengthProptMap[type]	=	TipsMainLogic.instance.getColorHtml(" (+"+value+")","ffffff");
					tips	=	"";
					
				}
				
			}
			else if(Ptype	==	MODIFY)
			{
				//				if(propertyList[])
				tips	=	con(StaticIni.getSwfLangStr("F_Gem_13234"));
			}
			if(tips)
				tips 	=	tips.concat(getChangeLine());
			return tips;
			function con(str:String):String
			{
				return tips.concat(link_color(str, color));
			}
		}
		public function getDisCount():String
		{
//			（装备等级-人物等级)/（装备等级-1）*65%
			var currentD:Number=_disCount;
			var countStr:String=(currentD*100).toFixed(1)
			if(currentD!=1)
			{
				return StaticIni.getSwfLangStrVar("UIString_1000291",[countStr])
			}
			else
			{
				return "";
			}

		}
		
		/**
		 *装备等级需要 
		 * @return 
		 * 
		 */		
		internal function getEqNeedLevel():String
		{
			var needlv:String	= _data["NeedLevel"];
			var str:String="";
			if(needlv != null && needlv != "")
			{
				var temp:String				= StaticIni.getSwfLangStr("ItemDes_NeedLevel");
				var tmpStr:String	= "";
				tmpStr				= tmpStr.concat(temp);
				tmpStr				= tmpStr.concat(needlv);
				var userLevel:String	=	_roleObj.GetPropertiesEx("Level");
				if(userLevel!= null && userLevel != "")
				{
					if(int(userLevel)>=int(needlv))
					{
						str				= str.concat(tmpStr);
					}else{
						str				= str.concat("<font color='#E8912E'>"+tmpStr+"</font>");
					}
				}
			}
			if(str)
			return 	str+getDisCount()+getChangeLine();
			return ""
		}
		/**
		 *	获取装备战斗力评分 
		 * @return 
		 * 
		 */		
		internal function getEquipFightScore():String
		{
//			var serverObj:BaseObject=_dataObj;
			var mainData:Object=_data//serverObj?serverObj.Properties:_data;
			var itemFightPower : int =  mainData["ItemFightPower"] ;
			
			//			return StaticIni.getSwfLangStrVar( "FightPower_1", [ int( serverObj.GetProperties( "JewelFightPower" ) )
			//				+ int( serverObj.GetProperties( "UpgradeFightPower" ) ) ] );
			
			//			//装备基础评分
			//			var equitScore 	: String =  StaticIni.getSwfLangStrVar( "FightPower_1", 
			//										[ StaticIni.getIniVar( configID, "ItemFightPower" ) ] );
			//			//宝石评分
			var jpgradeFightPower 	: int;
			//强化评分
			var jewelFightPower		: int;
			//		//附加评分
			var power				: int;
			//				
			if( mainData[ "JewelFightPower" ] )
			{
				//宝石评分
				jpgradeFightPower = int( mainData[ "JewelFightPower" ] );
			}
			if( mainData[ "UpgradeFightPower" ] )
			{
				//强化评分
				jewelFightPower = int( mainData[ "UpgradeFightPower" ] );
			}
			power = itemFightPower + jpgradeFightPower + jewelFightPower;
			
			return StaticIni.getSwfLangStrVar( "FightPower_1", [ power ] )	+	getChangeLine();
		}
		override public function getName():String
		{
			return StaticIni.getSwfLangStrVar("Tips_name",[link_color(super.getName()+getEqStrength(),_data["Color"])]);
		}
	}
}